package cs.java.event;

import static cs.java.lang.Lang.exception;
import static cs.java.lang.Lang.map;

import cs.java.collections.Map;
import cs.java.event.Event.EventRegistration;

public class EventConsumerImpl implements EventConsumer {
	private final Map<String, EventRegistration> registrations = map();

	public void addRegistration(String id, EventRegistration registration) {
		if (registrations.hasKey(id)) throw exception("Allready listening to this event", id);
		registrations.put(id, registration);
	}

	public void cancelRegistrations() {
		for (EventRegistration reg : registrations.values())
			reg.cancel();
		registrations.clear();
	}

	public EventRegistration removeRegistration(String id) {
		return registrations.remove(id);
	}
}
